<?php
/**
 * 【重要】并发器
 * Enter description here ...
 * @author hxm
 *
 */
class SoftBase {
	
	public static $config = null;
	
	public static $callAction = null;
	
	/**
	 * return vewrsion
	 * Enter description here ...
	 */
	public static function version() {
		
		return "v0.01";
	}
	
	/**
	 * Enter description here ...
	 * @param unknown_type $config
	 */
	public static function createApp($config) {
		self::$config = require_once($config);
		self::run();
	}
	
	/** 
	 * Enter description here ...
	 * @param unknown_type $className
	 */
	public static function autoload($className) {
		
		if (strrpos($className,'Model')) {
			//model 加载
			$fileDir =  self::$config['basePath'].'models/'.$className.'.php';
		} else {
			$fileBase = self::fielBase();
			$fileDir = dirname(__FILE__).$fileBase[$className];
		}
		if(file_exists($fileDir)) {
			include($fileDir);
			
		} else {
			throw new Exception ('does not match class File '.$fileDir);
		}
	}
	
	/**
	 * 启动soft
	 * Enter description here ...
	 */
	public static function run() {
		$Rewrite = new CRewriteUrl(self::$config);
		$route   = CRewriteUrl::route();
		self::$callAction = $route;
		self::callAction();
	}
	
	/**
	 * 呼叫控制
	 * Enter description here ...
	 * @param unknown_type $route
	 */
	public static function callAction() {
		$CAction = new CAction();
		return $CAction->call();
	}
	
	/**
	 * 文件配置
	 * Enter description here ...
	 */
	public static function fielBase() {
	
		return array(	
			'CRewriteUrl'   => '/base/CRewriteUrl.php',
			'CCache'        => '/caching/CCache.php',
			'CPdo'          => '/db/CPdo.php',
			'CActiveRecord' => '/base/CActiveRecord.php',
			'CAction'       => '/base/CAction.php',
			'CCacheFile'    => '/caching/CCacheFile.php',
			'CCacheData'    => '/caching/CCacheData.php',
			'CCacheMemcache'=> '/caching/CCacheMemcache.php',
			'CHttpCookie'   => '/base/CHttpCookie.php',
			'CServerSeeion' => '/base/CserverSeeion.php',
		);
	}
	
	/**
	 * 创建目录
	 * Enter description here ...
	 */
	public static function mkdir($dir) {
		
		mkdir($dir);
		@chmod($dir, 0777);
	}
	
	/**
	 * 文件创建
	 * Enter description here ...
	 * @param unknown_type $dir
	 */
	public static function mkfile($dir) {
		$fh = fopen($dir,'w+');
		fclose($fh);
	}
}
spl_autoload_register(array('SoftBase','autoload'));